'''
Created on 29/09/2011

@author: Ike-kun <ragnell22@gmail.com>
'''

class Filter(object):
    def __init__(self,dataReader):
        self.dataReaded = dataReader

    def doFilter(self,filters,comboSelection):
        newData = []
        skip = 0
        for i in range(len(self.dataReaded)):
            if(i == skip):
                if(i%5==0 and self.dataReaded[i].find(filters[0]) != -1):
                    newData = self.filterData(0,newData,i)
                    skip = i + 5
                elif(i%5==1 and self.dataReaded[i].strip() == comboSelection):
                    newData = self.filterData(1,newData,i)
                    skip = i + 4
                elif(i%5==2 and self.dataReaded[i].find(filters[1]) != -1):
                    newData = self.filterData(2,newData,i)
                    skip = i + 3
                elif(i%5==3 and self.dataReaded[i].find(filters[2]) != -1):
                    newData = self.filterData(3,newData,i)
                    skip = i + 2
                elif(i%5==4 and self.dataReaded[i].find(filters[3]) != -1):
                    newData = self.filterData(4,newData,i)
                    skip = i + 1
                else:
                    skip = i + 1
        return newData

    def filterData(self,id,newData,i):
        newData.append(self.dataReaded[i-id])
        newData.append(self.dataReaded[i+1-id])
        newData.append(self.dataReaded[i+2-id])
        newData.append(self.dataReaded[i+3-id])
        newData.append(self.dataReaded[i+4-id])
        return newData
